package PTA_5;

import java.util.Arrays;
import java.util.Scanner;

public class t3 {
    public static String sub(String str,int start,int end) {
        return new StringBuffer(str).substring(start,end).toString();
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String[] idnum = new String[n];
        String[] year = new String[n];
        for (int i = 0; i < n; i++) {
            idnum[i] = scan.next();
            idnum[i] = sub(idnum[i],6,14);
        }
        Arrays.sort(idnum);
        for (int i = 0; i < n; i++) {
            System.out.println(sub(idnum[i],0,4)+"-"
                                +sub(idnum[i],4,6)+"-"
                                +sub(idnum[i],6,8));
        }
    }
}
